package com.ruoyi.report.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.DimChina;
import com.ruoyi.report.service.IDimChinaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 中国省市区维度Controller
 * 
 * @author 李守壮
 * @date 2023-03-16
 */
@RestController
@RequestMapping("/report/dimChina")
public class DimChinaController extends BaseController
{
    @Autowired
    private IDimChinaService dimChinaService;

    /**
     * 查询中国省市区维度列表
     */
    @PreAuthorize("@ss.hasPermi('report:dimChina:list')")
    @GetMapping("/list")
    public TableDataInfo list(DimChina dimChina)
    {
        startPage();
        List<DimChina> list = dimChinaService.selectDimChinaList(dimChina);
        return getDataTable(list);
    }

    /**
     * 导出中国省市区维度列表
     */
    @PreAuthorize("@ss.hasPermi('report:dimChina:export')")
    @Log(title = "中国省市区维度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DimChina dimChina)
    {
        List<DimChina> list = dimChinaService.selectDimChinaList(dimChina);
        ExcelUtil<DimChina> util = new ExcelUtil<DimChina>(DimChina.class);
        util.exportExcel(response, list, "中国省市区维度数据");
    }

    /**
     * 获取中国省市区维度详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:dimChina:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dimChinaService.selectDimChinaById(id));
    }

    /**
     * 新增中国省市区维度
     */
    @PreAuthorize("@ss.hasPermi('report:dimChina:add')")
    @Log(title = "中国省市区维度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DimChina dimChina)
    {
        return toAjax(dimChinaService.insertDimChina(dimChina));
    }

    /**
     * 修改中国省市区维度
     */
    @PreAuthorize("@ss.hasPermi('report:dimChina:edit')")
    @Log(title = "中国省市区维度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DimChina dimChina)
    {
        return toAjax(dimChinaService.updateDimChina(dimChina));
    }

    /**
     * 删除中国省市区维度
     */
    @PreAuthorize("@ss.hasPermi('report:dimChina:remove')")
    @Log(title = "中国省市区维度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dimChinaService.deleteDimChinaByIds(ids));
    }


    /**
     * 导入
     */
    @Log(title = "DimChina", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('report:dimChina:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<DimChina> util = new ExcelUtil<DimChina>(DimChina.class);
        List<DimChina> list = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = dimChinaService.importData(list, updateSupport, operName);
        return success(message);
    }
    /**
     * 导入模版
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<DimChina> util = new ExcelUtil<DimChina>(DimChina.class);
        util.importTemplateExcel(response, "数据");
    }

}
